package la.bbs558.controller.admin;

import cn.dev33.satoken.annotation.SaIgnore;
import la.bbs558.controller.base.Result;
import la.bbs558.entity.params.UserSignInParams;
import la.bbs558.satoken.StpAdminUtil;
import la.bbs558.service.UserService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: Shanks
 * @date: 2023/12/15 10:43
 * @desc:
 */

@RestController
@RequestMapping("/admin")
@RequiredArgsConstructor
@SaIgnore
public class LoginController {

    private final UserService userService;

    @PostMapping("/login")
    public Result<?> login(@RequestBody UserSignInParams signInParams) {
        return Result.success(userService.signInForAdmin(signInParams));
    }

    @PostMapping("/logout")
    public Result<?> logout() {
        StpAdminUtil.logout();
        return Result.success();
    }
}
